package blackpai.backend.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("redis")
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("setVerifyCode")
    public String testString(String verifycode){
        System.out.println(verifycode+".............");
        Long pushAll = redisTemplate.opsForList().leftPushAll("verifycode",verifycode);
        return "success";
    }

    @RequestMapping("getVerifyCode")
    public List<String> getVerifyCode(){
        List<String> verifycode = redisTemplate.opsForList().range("verifycode", 0, -1);
        return verifycode;
    }

    @RequestMapping("setToken")
    public String setToken(String tokens,String managerId){
        redisTemplate.opsForValue().set(tokens, managerId);
        redisTemplate.expire(tokens,60*60*60 ,TimeUnit.SECONDS );
        return "添加成功";
    }

    @RequestMapping("getToken")
    public String getToken(String token){
        String tokens =(String) redisTemplate.opsForValue().get(token);
        return tokens;
    }

}
